package gdconf

import (
	"server_cluster/common/logger"
)

// 武器星级配置表

type WeaponStarConfig struct {
	Id        int32            `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 武器等级id
	StarGroup int32            `csv:"StarGroup,omitempty"`                       // 升星组
	Star      int32            `csv:"Star,omitempty"`                            // 星级
	Passive   IntArray         `csv:"Passive,omitempty"`                         // 被动
	Attribute FightPropAddList `csv:"Attribute,omitempty"`                       // 属性
}

func (w *WeaponStarConfig) TableName() string {
	return "config_weapon_star"
}

func (g *GameDataConfig) saveWeaponStarConfig() {
	saveTableToDb[WeaponStarConfig](g.Db, readTable[WeaponStarConfig](g.CsvPathPrefix+"Weaponstar.csv"))
}

func (g *GameDataConfig) loadWeaponStarConfig() {
	g.GameDataMaps.WeaponStarConfigMap = make(map[int32]map[int32]*WeaponStarConfig)
	for _, weaponStarConfig := range loadTableFromDb[WeaponStarConfig](g.Db) {
		_, exist := g.GameDataMaps.WeaponStarConfigMap[weaponStarConfig.StarGroup]
		if !exist {
			g.GameDataMaps.WeaponStarConfigMap[weaponStarConfig.StarGroup] = make(map[int32]*WeaponStarConfig)
		}
		g.GameDataMaps.WeaponStarConfigMap[weaponStarConfig.StarGroup][weaponStarConfig.Star] = weaponStarConfig
	}
	logger.Info("WeaponStarConfig Count: %v", len(g.GameDataMaps.WeaponStarConfigMap))
}

func GetWeaponStarConfigByGroupAndStar(group int32, star int32) *WeaponStarConfig {
	value1, exist := CONF.GameDataMaps.WeaponStarConfigMap[group]
	if !exist {
		logger.Error("[ConfigNotFound] WeaponStarConfig, group: %v, star: %v", group, star)
		return nil
	}
	value2, exist := value1[star]
	if !exist {
		logger.Error("[ConfigNotFound] WeaponStarConfig, group: %v, star: %v", group, star)
		return nil
	}
	return value2
}

func GetWeaponStarConfigMap() map[int32]map[int32]*WeaponStarConfig {
	return CONF.GameDataMaps.WeaponStarConfigMap
}
